package org.linys.dao.station;

import java.util.List;

import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import org.linys.model.station.Station;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@SuppressWarnings("unchecked")
@Repository
public class StationDAO {

	private SqlSession sqlSession;
	@Autowired
	public void setSqlSession(SqlSession sqlSession) {
		this.sqlSession = sqlSession;
	}
	
	public int count(Station station) {
		return (Integer) sqlSession.selectOne("StationMapper.count", station);
	}

	
	public List<Station> view(Station station, Integer start, Integer rows) {
		return (List<Station>) sqlSession.selectList("StationMapper.view",station,new RowBounds(start,rows));
	}

	public int save(Station station) {
		return sqlSession.insert("StationMapper.insert", station);
	}

	public int update(Station station) {
		return sqlSession.update("StationMapper.update", station);
	}

	public int deleteByID(Integer id) {
		return sqlSession.delete("StationMapper.delete", id);
	}

	public List<Station> viewChoose(Station station, Integer start, Integer rows) {
		return (List<Station>) sqlSession.selectList("StationMapper.viewChoose",station,new RowBounds(start,rows));
	}

	public int countChoose(Station station) {
		return (Integer) sqlSession.selectOne("StationMapper.countChoose",station);
	}

}
